//
//  XXIncomeTaxCalculationViewController.m
//  XingXue
//
//  Created by XingXue on 2024/1/30.
//  Copyright © 2024 XingXue. All rights reserved.
//

#import "XXIncomeTaxCalculationViewController.h"

#import "XXIncomeTaxCalculationTextCell.h"
#import "XXIncomeTaxCalculationTimeSelectCell.h"
#import "XXIncomeTaxCalculationButtonCell.h"
#import "XXIncomeTaxCalculationTipCell.h"

@interface XXIncomeTaxCalculationViewController ()

@property (nonatomic,copy) NSString *grossPay;//税前工资
@property (nonatomic,copy) NSString *type;//计算方式
@property (nonatomic,copy) NSString *socialSecurityMoney;//社保缴纳金额
@property (nonatomic,copy) NSString *accumulationFundMoney;//公积金缴纳金额
@property (nonatomic,copy) NSString *special;//专项附加扣除金额
@property (nonatomic,copy) NSString *other;//其他扣除金额

@end

@implementation XXIncomeTaxCalculationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _type = @"按月计算";
    
    [self setNavigationItemTitleViewWithTitle:@"个人所得税计算"];

    [self.tableView registerNib:[UINib nibWithNibName:@"XXIncomeTaxCalculationTextCell" bundle:nil] forCellReuseIdentifier:@"XXIncomeTaxCalculationTextCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"XXIncomeTaxCalculationTimeSelectCell" bundle:nil] forCellReuseIdentifier:@"XXIncomeTaxCalculationTimeSelectCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"XXIncomeTaxCalculationButtonCell" bundle:nil] forCellReuseIdentifier:@"XXIncomeTaxCalculationButtonCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"XXIncomeTaxCalculationTipCell" bundle:nil] forCellReuseIdentifier:@"XXIncomeTaxCalculationTipCell"];
    
    self.tableView.frame = CGRectMake(0,self.navigationBarHeight, kScreenWidth, kScreenHeight - self.navigationBarHeight);
    [self.view bringSubviewToFront:self.navigationBar];
}

#pragma mark - cellDataSource

- (NSArray *)cellDataSource {
    
    if (!self.dataSource) {
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
        
        __block NSMutableArray *subarr = nil;
        __block NSDictionary *dict = nil;
        
        subarr = [NSMutableArray arrayWithCapacity:1];

        //请输入金额
        dict =  @{@"class":XXIncomeTaxCalculationTextCell.class,
                  @"height":@([XXIncomeTaxCalculationTextCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTextCellModel ittemModelWithTitle:@"税前工资" content:_grossPay tip:@"请输入金额" position:0],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        //计算方式
        dict =  @{@"class":XXIncomeTaxCalculationTimeSelectCell.class,
                  @"height":@([XXIncomeTaxCalculationTimeSelectCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTimeSelectCellModel ittemModelWithTitle:@"计算方式" content:_type position:1],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        //社保缴纳金额
        dict =  @{@"class":XXIncomeTaxCalculationTextCell.class,
                  @"height":@([XXIncomeTaxCalculationTextCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTextCellModel ittemModelWithTitle:@"社保缴纳金额" content:_socialSecurityMoney tip:@"请输入具体缴纳金额" position:1],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        //公积金缴纳金额
        dict =  @{@"class":XXIncomeTaxCalculationTextCell.class,
                  @"height":@([XXIncomeTaxCalculationTextCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTextCellModel ittemModelWithTitle:@"公积金缴纳金额" content:_accumulationFundMoney tip:@"请输入具体缴纳金额" position:1],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        //专项附加扣除金额
        dict =  @{@"class":XXIncomeTaxCalculationTextCell.class,
                  @"height":@([XXIncomeTaxCalculationTextCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTextCellModel ittemModelWithTitle:@"专项附加扣除金额" content:_special tip:@"请输入具体缴纳金额" position:1],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        //其他扣除金额
        dict =  @{@"class":XXIncomeTaxCalculationTextCell.class,
                  @"height":@([XXIncomeTaxCalculationTextCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTextCellModel ittemModelWithTitle:@"其他扣除金额" content:_other tip:@"请输入金额" position:2],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        dict =  @{@"class":XXIncomeTaxCalculationButtonCell.class,
                  @"height":@([XXIncomeTaxCalculationButtonCell getCellFrame:[NSNumber numberWithFloat:110]]),
                  @"data":[XXIncomeTaxCalculationButtonCellModel ittemModelWithTitle:@"计算"],
                  @"delegate":@YES};
        [subarr addObject:dict];

        dict =  @{@"class":XXIncomeTaxCalculationTipCell.class,
                  @"height":@([XXIncomeTaxCalculationTipCell getCellFrame:[NSNumber numberWithFloat:20]]),
                  @"data":[XXIncomeTaxCalculationTipCellModel ittemModelWithTitle:@"若没有专项附加/其他扣除金额，请输入0"],
                  @"delegate":@YES};
        [subarr addObject:dict];
                
        [arr addObject:subarr];

        self.dataSource = arr;
    }
    return self.dataSource;
}

#pragma mark XXIncomeTaxCalculationTextCellDelegate 税前工资 社保缴纳金额 公积金缴纳金额 专项附加扣除金额 其他扣除金额
 
- (void)incomeTaxCalculationTextCell:(XXIncomeTaxCalculationTextCell *)cell textField:(UITextField *)textField {
    if ([cell.model.title isEqualToString:@"税前工资"]) {
        _grossPay = textField.text;
    } else if ([cell.model.title isEqualToString:@"社保缴纳金额"]) {
        _socialSecurityMoney = textField.text;
    } else if ([cell.model.title isEqualToString:@"公积金缴纳金额"]) {
        _accumulationFundMoney = textField.text;
    } else if ([cell.model.title isEqualToString:@"专项附加扣除金额"]) {
        _special = textField.text;
    } else if ([cell.model.title isEqualToString:@"其他扣除金额"]) {
        _other = textField.text;
    }
}

#pragma mark - XXIncomeTaxCalculationTimeSelectCellDelegate 计算方式

- (void)incomeTaxCalculationTimeSelectCell:(XXIncomeTaxCalculationTimeSelectCell *)cell buttonAction:(UIButton *)sender {
    
}

#pragma mark - QBincomeTaxCalculationButtonCellDelegate 计算

- (void)incomeTaxCalculationButtonCell:(XXIncomeTaxCalculationButtonCell *)cell button:(UIButton *)sender {
    [self countButtonAction:sender];
}

#pragma mark - Action

//计算
- (void)countButtonAction:(UIButton *)sender {
    __block NSString *erro = @"";

    if (_other.length == 0) {
        erro = @"请输入其他扣除金额";
    }

    if (_special.length == 0) {
        erro = @"请输入专项附加扣除金额";
    }

    if (_accumulationFundMoney.length == 0) {
        erro = @"请输入公积金缴纳金额";
    }

    if (_socialSecurityMoney.length == 0) {
        erro = @"请输入社保缴纳金额";
    }

    if (_grossPay.length == 0) {
        erro = @"请输入税前工资";
    }

    if (erro.length > 0) {
        [self showProgressHUD:erro];
    } else {
        [self gotoGroupingResultsViewController];
    }
}

#pragma mark - goto

//添加内容
- (void)gotoGroupingResultsViewController {
//    DYGroupingResultsViewController *vc = [DYGroupingResultsViewController new];
//    vc.name = _name;
//    vc.count = _count;
//    vc.groupList = _groupList;
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
}

@end
